package tech.daoxuan.security.core.validate.code.sms;

import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;
import tech.daoxuan.security.core.properties.SecurityProperties;
import tech.daoxuan.security.core.validate.code.ValidateCode;
import tech.daoxuan.security.core.validate.code.ValidateCodeGenerator;

/**
 * @ClassName ImageCodeGenerator
 * @Description TODO
 * @Author 10983
 * @Date 2019/6/22 17:55
 * @Version 1.0
 */
@Component
public class SmsCodeGenerator implements ValidateCodeGenerator{
    @Autowired
    private SecurityProperties securityProperties;
    @Override
    public ValidateCode generate(ServletWebRequest request) {
        String s = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLenght());
        return new ValidateCode( s,securityProperties.getCode().getImage().getExpireIn());
    }

    public SecurityProperties getSecurityProperties() {
        return securityProperties;
    }

    public void setSecurityProperties(SecurityProperties securityProperties) {
        this.securityProperties = securityProperties;
    }
}
